package com.zy.stock.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zy.stock.domain.Pager;
import com.zy.stock.domain.StockCrawlRecord;
import com.zy.stock.dto.StockCrawlRecordDto;
import com.zy.stock.mapper.StockCrawlRecordMapper;
import com.zy.stock.service.StockCrawlRecordService;
import com.zy.stock.util.CommonUtils;

@Component
@Transactional
public class StockCrawlRecordServiceImpl implements StockCrawlRecordService{
	
	@Autowired
	private StockCrawlRecordMapper stockCrawlRecordMapper;
	
	@Override
	public Pager<List<StockCrawlRecord>> findByCase(
			Pager<StockCrawlRecordDto> pager) throws Exception {
		// TODO Auto-generated method stub
		Pager<List<StockCrawlRecord>> result = new Pager<List<StockCrawlRecord>>();
		try{
			StockCrawlRecordDto obj = pager.getT();
			Integer total = stockCrawlRecordMapper.getCount(obj);
			Integer totalpage = CommonUtils.getTotalPage(pager, total);
			Integer begin = (pager.getPagenow() - 1) * pager.getSize();
			obj.setStart(begin);
			obj.setSize(pager.getSize());
			obj.setOrder(pager.getOrder());
			obj.setOrderCol(pager.getOrderCol());
			List<StockCrawlRecord> list = stockCrawlRecordMapper.findByCase(obj);
			result.setTotal(total);
			result.setT(list);
			result.setTotalpage(totalpage);
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception("StockOperationRecordServiceImpl.class findByCase function error : " + e.toString());
		}
		return result;
	}

	@Override
	public Integer save(StockCrawlRecord record) {
		// TODO Auto-generated method stub
		return stockCrawlRecordMapper.save(record);
	}

	@Override
	public StockCrawlRecord findById(Integer id) {
		// TODO Auto-generated method stub
		return stockCrawlRecordMapper.findById(id);
	}

  @Override
  public void ignoreYesterday() {
    // TODO Auto-generated method stub
    stockCrawlRecordMapper.ignoreYesterday();
  }

}
